<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>    
    <meta charset="UTF-8">
       
    <meta name="viewport" content="width=device-width, initial-scale=1, maximumscale=1">
       <title>Title</title>    
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all"/>
</head>
<body>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script type="text/javascript" src="/resources/js/jquery-1.12.3.min.js"></script>
<script th:inline="none">
    //Demo
    layui.use(['layer', 'form', 'table'], function () {
        var layer = layui.layer
            , form = layui.form
            , table = layui.table
            , $ = layui.jquery;//引入jquery
        var id = $("#breakId").val();
        //根据父页面传来的id获取车辆信息并回填
        $.ajax({

            type: "get",
            url: "/maintainrecord/maintainRecordById",
            data: {id: id},
            success: function (resp) {
                console.log(resp.data.maintainRecordById);
                var breakrulerecord = resp.data.maintainRecordById;
                $("#vid").val(breakrulerecord.vid);
                $("#mtid").val(breakrulerecord.mtid);
                $("#time").val(breakrulerecord.time);
                $(":text[name=cost]").val(breakrulerecord.cost);
                $("#muid").val(breakrulerecord.muid);
                $(":text[name=nowmileage]").val(breakrulerecord.nowmileage);
                $(":text[name=content]").val(breakrulerecord.content);
                $("#nexttime").val(breakrulerecord.nexttime);
                $(":text[name=nextmileage]").val(breakrulerecord.nextmileage);
                $(":text[name=information]").val(breakrulerecord.information);
                $("#driverid").val(breakrulerecord.driverid);
            }
        });
        $.ajax({
            type: "GET",
            url: "/vehiclefiles/selectVehicleAll",
            success: function (res) {
                var vehiclefiles = res.data.vehiclefilesList;
                if (vehiclefiles.length > 0) {
                    for (var i = 0; i < vehiclefiles.length; i++) {
                        var vehiclefile = vehiclefiles[i];
                        var sele = '';
                        if (vehiclefile.id == $("#vid").val()) {

                            sele = 'selected';
                        }
                        //追加，注意有坑，需要渲染下拉菜单
                        $("#vehiclenum").append("<option value='" + vehiclefile.id + "' selected='" + sele + "'>" + vehiclefile.vehiclenum + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        })
        $.ajax({
            type: "GET",
            url: "/dictionary/dictionaryType10",
            success: function (res) {
                var dictionarys = res.data.dictionaryList;
                if (dictionarys.length > 0) {
                    for (var i = 0; i < dictionarys.length; i++) {
                        var dictionary = dictionarys[i];
                        var sele = '';
                        if (dictionary.id == $("#muid").val()) {
                            sele = 'selected';
                        }
                        $("#muid").append("<option value='" + dictionary.id + "' selected='" + sele + "'>" + dictionary.name + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        })
        $.ajax({
            type: "GET",
            url: "/dictionary/dictionaryType11",
            success: function (res) {
                var dictionarys = res.data.dictionaryList;
                if (dictionarys.length > 0) {
                    for (var i = 0; i < dictionarys.length; i++) {
                        var dictionary = dictionarys[i];
                        var sele = '';
                        if (dictionary.id == $("#mtid").val()) {
                            sele = 'selected';
                        }
                        $("#mtid").append("<option value='" + dictionary.id + "' selected='" + sele + "'>" + dictionary.name + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        })
        $.ajax({
            type: "GET",
            url: "/driver/selectAllDriver",
            success: function (res) {
                var drivers = res.data.drivers;
                if (drivers.length > 0) {
                    for (var i = 0; i < drivers.length; i++) {
                        var driver = drivers[i];
                        var sele = '';
                        if (driver.id == $("#driverid").val()) {
                            sele = 'selected';
                        }
                        $("#driver").append("<option value='" + driver.id + "' selected='" + sele + "'>" + driver.name + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        });
    });
    var callbackdata = function () {
        var forms = $("#from2").serialize();
        return forms;
    }
</script>

<form class="layui-form" action="" method="" id="from2">

    <input type="hidden" name="id" id="breakId">
    <div class="layui-form-item">
        <label class="layui-form-label">车牌号码</label>
        <div class="layui-input-block">
            <select lay-verify="required"  name="vid" id="vehiclenum">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">保养类别</label>
        <div class="layui-input-block">
            <select lay-verify="required" name="mtid"  id="mtid">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">保养时间</label>
        <div class="layui-input-block">
            <input type="date" name="time" required  lay-verify="required" placeholder="请输入保养时间"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">保养金额</label>
        <div class="layui-input-block">
            <input type="text" name="cost" required  lay-verify="required" placeholder="请输入保养金额"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">保养单位</label>
        <div class="layui-input-block">
            <select lay-verify="required" name="muid"  id="muid">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">本次保养里程:</label>
        <div class="layui-input-block">
            <input type="text" name="nowmileage" required  lay-verify="required" placeholder="填写本次保养里程"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">保养内容</label>
        <div class="layui-input-block">
            <input type="text" name="content" required  lay-verify="required" placeholder="填写保养内容"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">下次保养时间</label>
        <div class="layui-input-block">
            <input type="date" name="nexttime" required  lay-verify="required" placeholder="填写下次保养时间"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">下次保养里程</label>
        <div class="layui-input-block">
            <input type="text" name="nextmileage" required  lay-verify="required" placeholder="填写下次保养里程"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注:</label>
        <div class="layui-input-block">
            <textarea  placeholder="请输入内容" class="layui-textarea" name="information"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">驾驶员</label>
        <div class="layui-input-block">
            <select lay-verify="required" id="driver" name="driverid">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
</form>


</body>
</html>